package com.xinai.adspter;

import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.xinai.R;

/**
 * Title: StockAdspter Description: 进出仓单ListView显示适配器(仓位管理)
 *
 * @author LYJ
 *
 */
public class StockAdspter extends BaseAdapter {

    private List<Map<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;

    public StockAdspter(Context context, List<Map<String, Object>> data) {
        this.context = context;
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
    }

    /**
     * 组件集合，对应list_stock.xml中的控件
     */
    public final class Zujian {
        public TextView number;
        public TextView customer;
        public TextView count;
        public TextView invoicedate;
    }

    public void refresh(List<Map<String, Object>> list) {
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    /**
     * 获得某一位置的数据
     */
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    /**
     * 获得唯一标识
     */
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Zujian zujian = null;
        if (convertView == null) {
            zujian = new Zujian();
            // 获得组件，实例化组件
            convertView = layoutInflater.inflate(R.layout.list_stock, null);
            zujian.number = (TextView) convertView.findViewById(R.id.tv_number);
            zujian.customer = (TextView) convertView.findViewById(R.id.tv_customer);
            zujian.count = (TextView) convertView.findViewById(R.id.tv_count);
            zujian.invoicedate = (TextView) convertView.findViewById(R.id.tv_invoicedate);
            convertView.setTag(zujian);
        } else {
            zujian = (Zujian) convertView.getTag();
        }
        // 绑定数据
        zujian.number.setText(String.valueOf(data.get(position).get("no")));
        zujian.customer.setText(String.valueOf(data.get(position).get("warehouseName")));//Department
        zujian.count.setText(String.valueOf(data.get(position).get("qtySum")));
      //  zujian.invoicedate.setText(String.valueOf(data.get(position).get("Date"))); // 之前为日期
        zujian.invoicedate.setText(String.valueOf(data.get(position).get("relationName")));//类别为1时为厂商ID，类别为2时为渠道ID,类别为3时为对    应出仓仓库ID
        return convertView;
    }

}
